Okay.
The next thing we need is script.
Is the message guy handler inside of our starter player scripts.
And this handler is going to be responsible for displaying typewriter style messages on the screen when
told to by the server.
So we have a guy in starter guy called our message guy.
And if we enable the visibility here, it's going to have basically three main areas to this guy.
One is it's going to display an image of the person who was talking.
It's going to display their name down here.
And then this section is where all the text is going to go.
And a typewriter effect is basically when we have the text slowly displaying out like it's being typed
while we play a sound effect with it.
So you can imagine as if the text was being typed out like this.
And it adds a nicer effect.
When we're trying to give messages to the player, we're going to be using this message UI frame mainly
just for our Squidward friend here, where he's going to be telling the players, uh, what to do and
kind of stuff like that.
So let me go ahead and disable visibility and let's get started in our message UI handler.
So inside of here we're going to need three services.
One is replicated storage.
We are going to need the player service.
And we're going to need the sound service.
Now we can create the table that will represent this module script.
We'll just call it GUI handler, return it at the end.
And then we want to have a few variables.
One is going to make a reference to the local player.
So players dot local player.
We want to make a reference to an event and replicated storage that will be used to tell our GUI handler
when to display messages on the screen, so we can call it Message Event, and it's in replicated storage,
dot events, dot remotes, dot message guy.
We also want to refer to our cam manipulation Bindable event and replicated storage dot events, dot
binding balls, dot manipulate camera.
And this is because our camera is going to be manipulated by another script to put it here, where it's
facing down at Squidward, and then it's going to tell this script to start displaying messages on the
screen.
When those messages are over, we want to reset the camera and put it back on the player.
So we're going to use our cam manipulation bindable to tell our camera manipulation handler to put the
player's camera back on their character.
That means we're also going to have to require our camera manipulation enum.
Which isn't replicated.
Storage.
Dot modules.
Dot enums.
Dot camera manipulation enum.
Next is we're going to make a reference to a sound and the sound service, which is our typewriter sound.
So that's an sound service guy.
And oops, looks like I required the wrong service up here for some reason.
We need the sound service, not the player service.
So guy dot typewriter.
So if we go inside of the sound service.
This is the sound we're going to play every time we display a character on the screen.
So just a simple click sound.
And then lastly, we need to make a reference to the message guy itself, which is going to be in the
local players player guy folder, and we want to wait for that to replicate.
From this point, we can create the function that's going to initialize our GUI handler.
And all this is going to do is listen to our message GUI event.
And we're going to connect a private function to this.
And we're going to call this private function on message event.
And it'll get passed some arguments.
So we don't need any actions for this because all this event is going to be used for is displaying messages
on the screen.
So we can connect it to our on message event function.
And what this will do is it'll get our message UI.
And inside of the frame of our message UI, there is an image label that will display the person who
is talking and the server is going to give to us through our args table, the image that we need to
set it to, so we can have a key inside of our args table like image, and set that to the image label
inside of the message UI dot frame, dot image label dot name label we have in there.
We want to set the text to the name of whoever is talking, so we can have another key that could say
something like who is speaking?
So this will give us a string of the name of the person that is talking.
The next thing we want to do inside the message UI dot frame is a message label in there, and we want
to set the text to be blank.
And then we want to set the message UI dot frame dot visibility equal to true.
So we can see it on our screen.
And then from this point we can have a for loop that loops through every single text or message that
is given to us in a table.
So inside of our args table we could have another table, and we could call it something like a message
table.
And it will just contain an array of strings that we need to loop through.
And then what we could do is we could loop through this text or through every single character in our
text.
So we could make a for loop, starting with an index of one all the way to the length of our text.
And what we could do is we could set the message GUI dot frame, dot message label dot text equal to.
And we're going to get a substring of this text starting at one all the way to the index of I, which
will be from this for loop right here.
And then we're going to play our typewriter sound.
And then after that, we need to have a delay between each character that we're displaying on the screen
so we can wait.
And then the server could also pass to us how long we need to wait.
So we could have another argument that could be like the delay between.
Characters in a string.
And then once it finally loops through the first string inside of this message table, then we need
to go to the next string.
But before we do that, we should have another wait statement outside of our second for loop before
we move on to the next text, and we could have another key value pair in our args table that defines
the delay we should have between the messages.
So we could call it delay between messages.
And then once we're done displaying all of the different messages on the screen, we can finally have
one more key value pair in our args table that tells us whether or not the camera was manipulated or
moved somewhere for this message to be displayed.
So in our case, we're going to be moving the player's camera to this C frame of this part right here.
And that's very important because we need to tell our message event function.
If we need to reset the camera back to the player.
So we could have a boolean like cam was manipulated for message.
If this is true then we need to use our cam manipulation Bindable and fire using the action of camera
manipulation enum dot two client dot reset camera.
So we want to move the camera back to its original state, and then after that we can set the message
UI dot frame dot visibility equal to false.
And that's all we need to do for our message UI handler.
Now we have all of these set up complete on the client side to start scripting our story in the next
lecture.
I'll see you there.